package com.nl.controller.web.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nl.controller.common.annotation.SystemServiceLog;
import com.nl.controller.common.exception.SmsException;
import com.nl.controller.common.service.CommonService;
import com.nl.controller.web.bean.SmsOperLog;
import com.nl.controller.web.mapper.SmsOperLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class SmsOperLogService {
@Autowired
    private SmsOperLogMapper smsOperLogMapper;

@Autowired
private CommonService commonService;
    @SystemServiceLog(description = "日志管理",value=false)
    public PageInfo<SmsOperLog> findOperLog(int page, int limit, String msisdn, String startTime, String endTime) {
        Map<String,Object> map = new HashMap<>();
        List<SmsOperLog> list=new ArrayList<>();
        map.put("msisdn",msisdn);
        map.put("startTime",startTime);
        map.put("endTime",endTime);
        PageHelper.startPage(page, limit);
        try {
            list = smsOperLogMapper.findOperLog(map);
            commonService.createSmsOperLog("4","查询日志","0","日志管理");
        }catch (Exception e) {
            commonService.createSmsOperLog("4","查询日志","1","日志管理");
            e.printStackTrace();
            log.error("日志管理查询出现异常：");
            throw new SmsException("日志管理出现异常：");
        }
        PageInfo<SmsOperLog> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}


